<?php
namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\App;

class NoChineseEmail implements Rule
{
    protected $blockedDomains = [
        'qq.com', '163.com', '126.com', 'sina.com',
        '139.com', '189.cn', 'sohu.com', 'aliyun.com',
        'yeah.net', '21cn.com',
    ];

    public function passes($attribute, $value)
    {
        $domain = strtolower(substr(strrchr($value, "@"), 1));
        return !in_array($domain, $this->blockedDomains);
    }

    public function message()
    {
        $lang = App::getLocale();

        if($lang == 'en') {
            return 'Please enter a valid email address.';
        } else {
            return '暫不支持中國大陸用戶註冊';
        }

    }
}

